package Game.Windows 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	/**
	 * ...
	 * @author Yevgeniy Logachev
	 */
	public class LoadingWindow
	{
		[Embed(source="../../../res/swf/loading.swf", symbol="loading")]
		public static var BackgroundClass:Class;
		
		[Embed(source="../../../res/swf/loading.swf", symbol="anim")]
		public static var AnimClass:Class;
		
		public static var 	m_loadingSprite:Sprite 	= null;
		public static var 	m_loadingAnim:Sprite 	= null;
		
		private static var 	m_show:Boolean			= false;
		private static var 	m_animTimer:Timer 		= null;
		
		private static const k_ANIM_SPEED:int		= 10;
		
		public static function set show(value:Boolean):void
		{
			m_show = value;
			if (m_show && m_loadingSprite == null)
			{
				m_loadingSprite = new Sprite();
				m_loadingAnim = new AnimClass();
				m_loadingAnim.x = Settings.screenWidth / 2;
				m_loadingAnim.y = Settings.screenHeight / 2;
				m_loadingSprite.addChild(new BackgroundClass());
				m_loadingSprite.addChild(m_loadingAnim);
				Main.mainSprite.addChild(m_loadingSprite);
				
				m_animTimer = new Timer(50);
				m_animTimer.addEventListener(TimerEvent.TIMER, update);
				m_animTimer.start();
			}
			else if(m_loadingSprite != null)
			{
				m_loadingSprite.removeChild(m_loadingAnim);
				m_loadingAnim = null;
				
				Main.mainSprite.removeChild(m_loadingSprite);
				m_loadingSprite = null;
				
				m_animTimer.removeEventListener(TimerEvent.TIMER, update);
				m_animTimer = null;
			}
		}
		
		public static function get show():Boolean
		{
			return m_show;
		}
		
		public static function update(e:TimerEvent):void
		{
			m_loadingAnim.rotation += k_ANIM_SPEED;
		}
	}

}